package com.example.hotel_lxy.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.hotel_lxy.R;
import com.ysxsoft.common_base.utils.DisplayUtils;


/**
* 性别选择
* create by Sincerly on 9999/9/9 0009
**/
public class SexDialog extends Dialog {
    private Context mContext;
    public SexDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.mContext = context;
        init();
    }

    private View init() {
        View view = View.inflate(mContext, R.layout.dialog_sex, null);
        TextView text_sex_nan=view.findViewById(R.id.text_sex_nan);
        TextView text_sex_nv=view.findViewById(R.id.text_sex_nv);
        TextView text_end=view.findViewById(R.id.text_end);

        text_sex_nan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onPositiveClick("1");
                dismiss();
            }
        });
        text_sex_nv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onPositiveClick("2");
                dismiss();
            }
        });
        text_end.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(true);
        setContentView(init());
    }

    public void showDialog() {
        if (!isShowing()) {
            show();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.height = DisplayUtils.getDisplayWidth(mContext) * 5 / 5;
            lp.width = DisplayUtils.getDisplayWidth(mContext) * 10 / 10;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            getWindow().setAttributes(lp);
            getWindow().setGravity(Gravity.BOTTOM);
        }
    }



    public static SexDialog show(Context context, OnDialogClickListener listener) {

        SexDialog dialog = new SexDialog(context, R.style.BottomDialogStyle);
        dialog.setListener(listener);
        dialog.showDialog();
        return dialog;
    }

    public OnDialogClickListener listener;

    public SexDialog setListener(OnDialogClickListener listener) {
        this.listener = listener;
        return this;
    }
    public interface OnDialogClickListener {
        /**
         * 点击确定按钮事件
         */
        public void onPositiveClick(String s);
    }
}